package com.zz.hhbl.ui.operationdemonstration.banner;

import android.view.View;

import com.shuyu.gsyvideoplayer.GSYVideoManager;
import com.shuyu.gsyvideoplayer.builder.GSYVideoOptionBuilder;
import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack;
import com.zz.hhbl.R;
import com.zz.hhbl.entity.SpotConfigEntity;
import com.zz.hhbl.player.EmptyControlVideo;
import com.zz.hhbl.utils.LocalUrlUtils;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

public class VideoHolder extends RecyclerView.ViewHolder {
    public static String TAG = "videoPlayer";
    public EmptyControlVideo gsyVideoPlayer;
    GSYVideoOptionBuilder gsyVideoOptionBuilder;

    public VideoHolder(@NonNull View view) {
        super(view);
        gsyVideoPlayer = view.findViewById(R.id.videoPlayer);
        gsyVideoOptionBuilder = new GSYVideoOptionBuilder();
    }

    public void onBind(final int position, @Nullable SpotConfigEntity item ){
        gsyVideoOptionBuilder
                .setIsTouchWiget(false)
                .setUrl(item==null?"": LocalUrlUtils.INSTANCE.getLocalUrl(item.getUrl()))
                .setVideoTitle("")
                .setCacheWithPlay(true)
                .setPlayTag(TAG)
                .setPlayPosition(position)
                .setVideoAllCallBack(new GSYSampleCallBack() {
                    @Override
                    public void onPrepared(String url, Object... objects) {
                        super.onPrepared(url, objects);
                        if (!gsyVideoPlayer.isIfCurrentIsFullscreen()) {
                            //静音
                            GSYVideoManager.instance().setNeedMute(false);
                        }
                    }

                    @Override
                    public void onAutoComplete(String url, Object... objects) {
                        super.onAutoComplete(url, objects);
                    }

                    @Override
                    public void onQuitFullscreen(String url, Object... objects) {
                        super.onQuitFullscreen(url, objects);
                        //全屏不静音
                        GSYVideoManager.instance().setNeedMute(false);
                    }

                    @Override
                    public void onEnterFullscreen(String url, Object... objects) {
                        super.onEnterFullscreen(url, objects);
                        GSYVideoManager.instance().setNeedMute(false);
                    }
                }).build(gsyVideoPlayer);
    }
}